package com.example.memorypoint.mvp.history;

import com.example.memorypoint.DateBase.DiaryDatabase;
import com.example.memorypoint.entity.Diary;
import java.util.List;

public class HistoryPresenterImpl implements HistoryContract.HistoryPresenter {

    private HistoryContract.HistoryView view;
    private DiaryDatabase diaryDatabase;

    public HistoryPresenterImpl(HistoryContract.HistoryView view, DiaryDatabase diaryDatabase) {
        this.view = view;
        this.diaryDatabase = diaryDatabase;
    }

    @Override
    public void loadHistory() {
        try {
            // 从数据库获取所有日记（按日期倒序排序）
            List<Diary> diaries = diaryDatabase.getDairyList();
            view.showHistory(diaries);
        } catch (Exception e) {
            view.showError("加载历史记录失败：" + e.getMessage());
        }
    }

    @Override
    public void detachView() {
        view = null;
    }
}
